package br.perfiman.faces;

import java.util.List;

import javax.faces.model.SelectItem;

import br.perfiman.helpers.GeneralComboHelper;
import br.perfiman.model.Account;
import br.perfiman.model.Bill;
import br.perfiman.model.Category;
import br.perfiman.model.CreditCard;
import br.perfiman.model.Person;
import br.perfiman.service.AbstractService;
import br.perfiman.utils.ServiceLocator;

public class BillBean extends AbstractBean<Bill> {

	public BillBean() throws Exception {
		super();
		if(getEntity() == null) {
			setEntity(new Bill());
			getEntity().setAccount(new Account());
			getEntity().setCreditCard(new CreditCard());
			getEntity().setCategory(new Category());
			getEntity().setInvolved(new Person());
		}
		retrieveAll();
	}

	@Override
	@SuppressWarnings("unchecked")
	protected AbstractService<Bill> getService() throws Exception {
		if(service == null){
			service = (AbstractService<Bill>) ServiceLocator.getInstance().get("BillServiceBean/remote");
		}
		return service;
	}

	public List<SelectItem> getAccounts() throws Exception{
		return GeneralComboHelper.getAccounts();
	}

	public List<SelectItem> getCategorys() throws Exception{
		return GeneralComboHelper.getCategorys();
	}

	public List<SelectItem> getCreditCards() throws Exception{
		return GeneralComboHelper.getCreditCards();
	}

	public List<SelectItem> getInvolveds() throws Exception{
		return GeneralComboHelper.getPersons();
	}
}
